#include "config.h"
#include "GPIO_InIt.h"
#include "MyTimer.h"
#include "IR_Exit.h"

u8 KeyNum;
u16 Time;

void UART_config(void)
{
	COMx_InitDefine		COMx_InitStructure;					
	COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;
	COMx_InitStructure.UART_BRT_Use   = BRT_Timer1;
	COMx_InitStructure.UART_BaudRate  = 9600;
	COMx_InitStructure.UART_RxEnable  = ENABLE;
	COMx_InitStructure.BaudRateDouble = DISABLE;
	COMx_InitStructure.UART_Interrupt = ENABLE;
	COMx_InitStructure.UART_Priority  = Priority_0;
	COMx_InitStructure.UART_P_SW      = UART1_SW_P30_P31;
	UART_Configuration(UART1, &COMx_InitStructure);
	EA=1;//中断总开关
}

unsigned char Key()
{
	unsigned char KeyNumber=0;
	
	if(Key1==0){Delay_ms(20);while(Key1==0);Delay_ms(20);KeyNumber=1;}
	if(Key2==0){Delay_ms(20);while(Key2==0);Delay_ms(20);KeyNumber=2;}
	if(Key3==0){Delay_ms(20);while(Key3==0);Delay_ms(20);KeyNumber=3;}
	if(Key4==0){Delay_ms(20);while(Key4==0);Delay_ms(20);KeyNumber=4;}
	
	return KeyNumber;
}

void main()
{
	GPIO_Init();
	UART_config();
//	Timer1_38KHZ();
	Timer0_Init();
	Exti_Init();
	
	while(1)
	{	
		TX1_write2buff(0xAA);
		Delay_ms(500);
		
//		KeyNum = Key();
//		if(KeyNum==1){W_Data(0x18);}
//		else if(KeyNum==2){W_Data(0x5E);}
	}
}


//void Ext_INT0 (void) interrupt INT0_VECTOR		//进中断时已经清除标志
//{
//	Delay_ms(20);
//	while(Key1==0);
//	Delay_ms(20);
//	KeyNum=1;
//}

//void Ext_INT1 (void) interrupt INT1_VECTOR		//进中断时已经清除标志
//{
//	Delay_ms(10);
//	while(Key2==0);
//	Delay_ms(10);
//	KeyNum=2;
//}

//void Ext_INT2 (void) interrupt INT2_VECTOR
//{
//	Delay_ms(10);
//	while(Key3==0);
//	Delay_ms(10);
//	KeyNum=3;
//}

//void Ext_INT3 (void) interrupt INT3_VECTOR
//{
//	Delay_ms(10);
//	while(Key4==0);
//	Delay_ms(10);
//	KeyNum=4;	
//}




